package com.base.vistter.iframe.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.base.vistter.iframe.entity.SysNoticeUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface SysNoticeUserMapper extends BaseMapper<SysNoticeUser> {

    @Select({"<script>" ,
            "SELECT count(0) FROM sys_notice_user snu",
            "LEFT JOIN sys_notice sn on snu.sys_notice_id = sn.id",
            "where snu.sys_user_id = #{userId} and snu.is_delete = 0 and sn.is_delete = 0 and sn.`status` = 0 and (sn.deadline is null or sn.deadline > NOW())",
            "<if test='title != null'>",
            "AND sn.title like '%${title}%'",
            "</if>",
            "</script>"})
    public long selectUserNoticeCount(@Param("userId") Integer userId, @Param("title") String title);

    @Select({"<script>" ,
            "SELECT snu.id, snu.status,sn.id as sys_notice_id, sn.type, sn.title, sn.priority, sn.create_date FROM sys_notice_user snu ",
            "LEFT JOIN sys_notice sn on snu.sys_notice_id = sn.id ",
            "where snu.sys_user_id = #{userId} and snu.is_delete = 0 and sn.is_delete = 0 and sn.`status` = 0 and (sn.deadline is null or sn.deadline > NOW()) ",
            "<if test='title != null'>",
            "AND sn.title like '%${title}%' ",
            "</if>",
            "ORDER BY snu.`status` asc , sn.create_date desc ",
            "limit #{start},#{size}",
            "</script>"})
    public List<SysNoticeUser> selectUserNotice(@Param("userId") Integer userId, @Param("title") String title, @Param("start") long start , @Param("size") long size);
}
